#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
const int N=2e5+10,M=2e5+10;
int n,fa[N],id,lim;
int f[N],g[N];
int solve0()
{
	for ( int i = 1 ; i <= n ; i++ )f[i]=g[i]=0;
	for ( int i = lim ; i > 1 ; i-- )
	{
		if(f[fa[i]]<f[i]+1)
		{
			g[fa[i]]=f[fa[i]];
			f[fa[i]]=f[i]+1;
		}else if(g[fa[i]]<f[i]+1)
			g[fa[i]]=f[i]+1;
	}
	int ans=0;
	for ( int i = 1 ; i <= lim ; i++ )ans=max(ans,f[i]+g[i]);
	return ans;
}
int check(int x,int y)
{
	//y\in subtree(x)--> 1
	while(y!=1)
	{
		if(y==x)return 1;
		y=fa[y];
	}
	return 0;
}
int solve()
{
	int ans=solve0();
	for ( int i = 2 ; i <= lim ; i++ )
	{
		for ( int j = i+1 ; j <= lim ; j++ )
		{
			if(check(i,j))continue;
			swap(fa[i],fa[j]);
			ans=max(ans,solve0());
			swap(fa[i],fa[j]);
		}
	}
	return ans;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("forest.in","r",stdin);
	freopen("forest.out","w",stdout);
	cin >> id >> n;
	int lstans=0;
	for ( int i = 2 ; i <= n ; i++ )
	{
		lim=i;
		cin >> fa[i];fa[i]^=lstans;
//		cerr << i << endl;
//		assert(fa[i]<i);
		cout << (lstans=solve()) << endl;
	}
	return 0;
}


